#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<string>
#include<vector>
using namespace std;

class Solution
{
public:
    vector<string> letterCombinations(string digits)
    {
        vector<string> v(9);
        v[0] += "abc";
        v[1] += "def";
        v[2] += "ghi";
        v[3] += "jkl";
        v[4] += "mno";
        v[5] += "pqrs";
        v[6] += "tuv";
        v[7] += "wxyz";

        int size = 1;
        for (int i = 0; i < digits.size(); ++i)
        {
            size *= v[digits[i] - '0'].size();
        }

        vector<string> ret(size);

        int sym = 0;

        for (int i = 0; i < ret.size(); ++i)
        {
            for (int j = digits.size() - 1; j >= 0; --j)
            {
                if (sym == v[j].size())
                {
                    sym = 0;
                }
                ret[i].push_back(v[digits[j] - '2'][sym]);
            }
            ++sym;
        }

        for (int i = 0; i < ret.size(); ++i)
        {
            reverse(ret[i].begin(), ret[i].end());
        }

        return ret;
    }
};

int main()
{
    string s1("23");
    Solution s;
    vector<string> ret = s.letterCombinations(s1);
    for (int i = 0; i < ret.size(); ++i)
    {
        cout << ret[i] << endl;
    }

	return 0;
}